package com.taxer.service.impl;

import com.taxer.db.dao.NewsMapper;
import com.taxer.db.entity.News;
import com.taxer.exception.TaxerExcepiton;
import com.taxer.service.NewsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("newsService")
public class NewsServiceImpl implements NewsService{
    @Resource
    private NewsMapper newsMapper;
    @Override
    public News getNewsById(Long id) {
        return newsMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<News> getNewsAll() {
        List<News> list=newsMapper.findAllNews();
        return list;
    }

    @Override
    public void insert(News news) throws TaxerExcepiton{

        try {
            newsMapper.insert(news);
        }catch (Exception e){
            throw new TaxerExcepiton("数据库异常");
        }
    }

    @Override
    public boolean deleteById(Long id) throws TaxerExcepiton{
        try {
            newsMapper.deleteByPrimaryKey(id);
            return true;
        }catch (Exception e){
            throw new TaxerExcepiton("数据库异常");
        }
    }

    @Override
    public boolean deleteBySomeId(List list) throws TaxerExcepiton{

        try {
            newsMapper.deleteSome(list);
            return true;
        }catch (Exception e){
            throw new TaxerExcepiton("数据库异常");
        }
    }
}
